package com.lap.framework.ddd;

import com.lap.framework.entity.AbstractAudit;
import java.util.ArrayList;
import java.util.List;
import lombok.EqualsAndHashCode;

/**
 * 领域模型聚合根抽象类
 *
 * @author Shuisheng Lao(劳水生)
 * @version 0.0.1
 */
@EqualsAndHashCode(callSuper = true)
public abstract class AggregateRoot extends AbstractAudit {
  private final List<DomainEvent> events = new ArrayList<>();

  protected void registerEvent(DomainEvent event) {
    events.add(event);
  }

  public List<DomainEvent> getEvent() {
    return List.copyOf(events);
  }

  public void clearEvents() {
    events.clear();
  }
}
